Function Reference

_TS_ActionDelete

Delete a single or all Action objects by ID or index.

#Include <TaskScheduler.au3>
_TS_ActionDelete($oTaskDefinition, $iIndex[, $sID = ""[, $bDeleteAll = False]])

 

Parameters

$oTaskDefinition Task Definition object of a new or Registered Task
$iIndex Delete the Action with the specified index (one based)
$sID [optional] Deletes all Actions with the same ID (default = "")
$bDeleteAll [optional] Removes all Actions (default = False)

 

Return Value

Success: 1
Failure: Returns 0 and sets @error:
    502 - The Action could not be deleted. @extended is set to the COM error code
    503 - The Actions could not be deleted. @extended is set to the COM error code
    504 - Either $iIndex or $sID has to be specified when $bDeleteAll is set to False

 

Remarks

Set one of this three parameters to delete specific or all Actions: $iIndex, $sID, $bDeleteAll.
The parameters will be processed in the following sequence:
If $iIndex > 0 then delete by index, else if $sID <> "" then delete by ID, else if $bDeleteAll is True then delete all Actions
|
When you used $bDeleteAll = True you have to create at least one Action object as you can't register a Task without Actions.

 

Related

 

Example


#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <TaskScheduler.au3>
#include <Array.au3>

Global $sFolder = "\Test"    ; Folder where to create the task
Global $sName = "Test-Task"  ; Name of the task to create

; *****************************************************************************
; Connect to the Task Scheduler Service
; *****************************************************************************
Global $oService = _TS_Open()
If @error <> 0 Then Exit MsgBox($MB_ICONERROR, "Task Scheduler UDF", "Error connecting to the Task Scheduler Service. @error = " & @error & ", @extended = " & @extended & @CRLF & @CRLF & _TS_ErrorText(@error))

Global $oTask = _TS_TaskGet($oService, $sFolder & "\" & $sName)
If @error <> 0 Then Exit MsgBox($MB_ICONERROR, "Task Scheduler UDF", "Error retrieving the specified Task. @error = " & @error & ", @extended = " & @extended & @CRLF & @CRLF & _TS_ErrorText(@error))
Global $oTaskDefinition = $oTask.Definition

; *****************************************************************************
; Delete all existing Actions
; *****************************************************************************
_TS_ActionDelete($oTaskDefinition, Default, Default, True)
If @error Then Exit MsgBox($MB_ICONERROR, "_TS_ActionDelete", "_TS_ActionDelete returned @error=" & @error & ", @extended=" & @extended & @CRLF & @CRLF & _TS_ErrorText(@error))
MsgBox($MB_ICONINFORMATION, "_TS_ActionDelete", "All existing Actions for Task '" & $sName & "' have been deleted!")

; *****************************************************************************
; Add two actions with different IDs to the Task
; *****************************************************************************
Global $sID1 = "Action-1"
Global $sID2 = "Action-2"
Global $oAction1 = _TS_ActionCreate($oTaskDefinition, $TASK_ACTION_EXEC, $sID1)
If @error Then Exit MsgBox($MB_ICONERROR, "_TS_ActionDelete", "Creating the Action returned @error=" & @error & ", @extended=" & @extended & @CRLF & @CRLF & _TS_ErrorText(@error))
Global $oAction2 = _TS_ActionCreate($oTaskDefinition, $TASK_ACTION_EXEC, $sID2)
If @error Then Exit MsgBox($MB_ICONERROR, "_TS_ActionDelete", "Creating the Action returned @error=" & @error & ", @extended=" & @extended & @CRLF & @CRLF & _TS_ErrorText(@error))

; *****************************************************************************
; Set the Action properties for both Actions
; *****************************************************************************
Global $aProperties[] = ["ACTIONS|Path|Action-1"]
_TS_TaskPropertiesSet($oAction1, $aProperties)
If @error Then Exit MsgBox($MB_ICONERROR, "_TS_ActionDelete", "_TS_TaskPropertiesSet for the Action returned @error=" & @error & ", @extended=" & @extended & @CRLF & @CRLF & _TS_ErrorText(@error))
$aProperties[0] = "ACTIONS|Path|Action-2"
_TS_TaskPropertiesSet($oAction2, $aProperties)
If @error Then Exit MsgBox($MB_ICONERROR, "_TS_ActionDelete", "_TS_TaskPropertiesSet for the Action returned @error=" & @error & ", @extended=" & @extended & @CRLF & @CRLF & _TS_ErrorText(@error))
MsgBox($MB_ICONINFORMATION, "_TS_ActionDelete", "Actions '" & $sID1 & "' and '" & $sID2 & "' for Task '" & $sName & "' have been created!")

; *****************************************************************************
; Delete the Action by ID
; *****************************************************************************
_TS_ActionDelete($oTaskDefinition, Default, $sID1)
If @error Then Exit MsgBox($MB_ICONERROR, "_TS_ActionDelete", "_TS_ActionDelete returned @error=" & @error & ", @extended=" & @extended & @CRLF & @CRLF & _TS_ErrorText(@error))

; *****************************************************************************
; Update the Task
; *****************************************************************************
_TS_TaskRegister($oService, $sFolder, $sName, $oTaskDefinition, Default, Default, Default, $TASK_UPDATE)
If @error Then Exit MsgBox($MB_ICONERROR, "_TS_ActionDelete", "_TS_TaskRegister returned @error=" & @error & ", @extended=" & @extended & @CRLF & @CRLF & _TS_ErrorText(@error))

MsgBox($MB_ICONINFORMATION, "_TS_ActionDelete", "Action '" & $sID1 & "' for Task '" & $sName & "' has been deleted!")

_TS_Close()